/** 
 * ================================================================================
 * 		Project		: Kompas Bola
 * 		File		: SplashActivity.java
 * 		Description	: Splash Screen
 * 		Called		: 
 * ================================================================================
 * */
package com.kompas.bola.application;

import java.util.HashMap;
import java.util.List;
import com.kompas.bola.application.R;
import com.google.analytics.tracking.android.EasyTracker;
import com.kompas.bola.application.analytics.FlurryUtil;
import com.kompas.bola.application.analytics.GAnalyticsUtil;
import com.kompas.bola.application.dao.Dao;
import com.kompas.bola.application.db.CrudHelper;
import com.kompas.bola.application.model.Content;
import com.kompas.bola.application.utils.Constants;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class SplashActivity extends Activity{
	/** =========================================================================== */		
	private static String TAG 					= SplashActivity.class.getName();
	private static long SLEEP_TIME 				= 5;
	int page 									= 1;
	private AsyncTask<String, Void, Content> mainTask;
	private HashMap<String, String> value;
	/** =========================================================================== */	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		setContentView(R.layout.splash_screen);				
		
		/** 
		 * START GOOGLE ANALYTICS */
		value									= new HashMap<String, String>();
		value.put(Constants.KOMPAS_BOLA, Constants.SPLASH_SCREEN);
		GAnalyticsUtil.startSessionWithGA(this,value);	
		
		IntentLauncher launcher = new IntentLauncher();
		launcher.start();
	}
	/** =========================================================================== */		
	private class IntentLauncher extends Thread{
		public void run(){
			try {
				Thread.sleep(SLEEP_TIME*1000);
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(TAG, e.getMessage());
			}            
            // Start main activity
          	Intent intent = new Intent(SplashActivity.this, MainActivity.class);
          	SplashActivity.this.startActivity(intent);
          	SplashActivity.this.finish();
		}		
	}
	/** =========================== s : Google Analytics ========================== */
	@Override
	public void onStart() {
		super.onStart();	    
		
		EasyTracker.getInstance(this).activityStart(this);  // Add this method.	
		FlurryUtil.startSessionWithFlurry(this, Constants.SPLASH_SCREEN);
	}
	/** =========================================================================== */
	@Override
	public void onStop() {
		super.onStop();
		
	    EasyTracker.getInstance(this).activityStop(this);  // Add this method.
		FlurryUtil.endSessionWithFlurry(this,  Constants.SPLASH_SCREEN);
	}
	/** =========================== e : Google Analytics ========================== */
}
